package tools.transeq;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;

import tools.hmmer.hmmerAlignment;
import tools.hmmer.hmmerModelAlignment;
import tools.hmmer.hmmerParser;

public class transeqUtils {

	public static void main(String[] args)throws Exception{
		if(args.length>0){
			if(args[0].equals("subTop")){
				if(args.length==3){
					
				}else{
					System.err.println(printHelp());
					System.exit(616);
				}
			}else{
				System.err.println(printHelp());
				System.exit(616);
			}
		}else{
			System.err.println(printHelp());
			System.exit(616);
		}
	}
	
	private static String printHelp(){
		String help="Usage: hmmerUtils <cmd> <input>\n";
		help+="where <cmd> is:\n";
		help+="subTop - extracts the top domains for a subset of the hmmerFile specified in the subSetFile\n";
		help+="\t<input> = <hmmerFile> <subSetFile>\n";
		
		
		return help;
	}
	private static void hmmerSort(String hmmerFile,double eCutoff,String outPrefix)throws Exception{
		HashMap<String, BufferedWriter> outs=new HashMap<String, BufferedWriter>();
		hmmerParser hp=new hmmerParser(new BufferedReader(new FileReader(hmmerFile)));
		hmmerAlignment ha;
		String curName,strand;
		for(;hp.hasMore();){
			ha=hp.nextHit();
			curName=ha.qname.substring(0,ha.qname.length()-3);
			if(!outs.containsKey(curName)){
				outs.put(curName, new BufferedWriter(new FileWriter(outPrefix+curName+"_hmm.gff")));
			}
			switch (ha.qname.charAt(ha.qname.length()-1)) {
			case '4':
				strand="-";
				break;
			case '5':
				strand="-";
				break;
			case '6':
				strand="-";
				break;
			default:
				strand="+";
				break;
			}
			for (hmmerModelAlignment hma : ha.hmms) {
				if(hma.eValue<=eCutoff){
					outs.get(curName).write(hma.toGFF(strand)+"\n");
				}
			}
		}
		for (BufferedWriter out : outs.values()) {
			out.close();
		}
	}
}
